#ifndef MAINWINDOW_H_D1
#define MAINWINDOW_H_D1

#include <QMainWindow>
#include <QTcpSocket>
#include <QHostAddress>
#include <QHostInfo>
#include <QComboBox>
#include <QSpinBox>
#include <QPushButton>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QCloseEvent>

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

protected:
    void closeEvent(QCloseEvent *event) override;

private:
    QTcpSocket *tcpclient;

    // UI widgets
    QComboBox *comboBoxIp;
    QSpinBox *spinBoxPort;
    QPushButton *pushButtonConnect;
    QPushButton *pushButtonDisconnect;
    QLineEdit *lineEditInputMsg;
    QPushButton *pushButtonSend;
    QPlainTextEdit *plainTextEditDispMsg;

    QString getLocalIp(); // 获取本机IP地址

private slots:
    void onConnectClicked();
    void onSendClicked();
    void onDisconnectClicked();

    void connectFunc();
    void disconnectFunc();
    void socketReadData();
};

#endif // MAINWINDOW_H
